﻿/*
* Copyright (C) 2023 ~ 2033 Ltd.
*
* Author:     helei <2454264168@qq.com>
*
* Maintainer: helei <2454264168@qq.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* General Public License version 3 as published by the Free Software
* Foundation and appearing in the file LICENSE.MIT included in the
* packaging of this file.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef UTAGWIDGET_H
#define UTAGWIDGET_H

#include "utkwidget_export.h"
#include "style/ustyleoption.h"

#include <QWidget>

class UTagWidgetPrivate;
class UTKWIDGET_EXPORT UTagWidget : public QWidget
{
    Q_OBJECT

public:
    explicit UTagWidget(QWidget* parent = nullptr);
    ~UTagWidget();

    void setButtonFeature(UTagWidgetStyleOption::TagFeature feature);

    void setBackgroundRole(int role);

    void setTextFormat(const Qt::TextFormat &format);

    void setText(const QString &text);

    QString text() const;

    QString plainText() const;

    void setMargin(int margins);

    void clear();

    void setEditEnable(bool enabled);

    bool editEnable() const;

private Q_SLOTS:
    void onEditFinished();

protected:
    void paintEvent(QPaintEvent*) override;

    virtual void initStyleOption(UTagWidgetStyleOption* option) const;

    void resizeEvent(QResizeEvent* event) override;

    QSize sizeHint() const override;

    QSize minimumSizeHint() const override;

    void mouseDoubleClickEvent(QMouseEvent* event) override;

private:
    QScopedPointer<UTagWidgetPrivate> d_ptr;
    Q_DISABLE_COPY(UTagWidget)
    Q_DECLARE_PRIVATE_D(d_ptr, UTagWidget)
};

#endif // UTAGWIDGET_H
